/**
 * 
 */
package com.lanswon.qzsmk.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.session.SessionException;
import org.apache.shiro.subject.Subject;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import ch.qos.logback.classic.Logger;

/**
 * shiro退出
 * @author sun
 *
 */
@Component
public class LogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter {

	private static Logger logger = (Logger) LoggerFactory.getLogger(LogoutFilter.class);

	@Override
	protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
		// 在这里执行退出系统前需要清空的数据
		Subject subject = getSubject(request, response);
		String redirectUrl = getRedirectUrl(request, response, subject);
		ServletContext context = request.getServletContext();
			logger.debug("用户[{}]退出成功", subject.getPrincipal());
			subject.logout();
			context.removeAttribute("error");
		issueRedirect(request, response, redirectUrl);
		return false;
	}
}
